<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="common/include :: header('预约列表')" />
</head>
<body class="gray-bg">
	<div class="container-div">
		<div class="row">
			<div class="col-sm-12 search-collapse">
				<form id="appointment-form">
					<div class="select-list">
						<ul>
							<li>
								预约名字：<input type="text" name="customerName"/>
							</li>
							<li>
								预约名字：<input type="text" name="customerPhone"/>
							</li>
							<li>
								状态：
								<select name="status" th:with="type=${@dict.getType('si_car_package')}">
									<option value="">所有</option>
									<option th:each="dict:${type}"
											th:text="${dict.label}"
											th:value="${dict.value}"></option>
								</select>
							</li>
							<li>
								服务类型：
								<select name="serviceCatalog" th:with="type=${@dict.getType('si_service_catalog')}">
									<option value="">所有</option>
									<option th:each="dict:${type}"
											th:text="${dict.label}"
											th:value="${dict.value}"></option>
								</select>
							</li>
							<li>
								审核状态：
								<select name="auditStatus" th:with="type=${@dict.getType('cmi_status')}">
									<option value="">所有</option>
									<option th:each="dict:${type}"
											th:text="${dict.label}"
											th:value="${dict.value}"></option>
								</select>
							</li>
							<li>
								<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
							    <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
							</li>
						</ul>
					</div>
				</form>
			</div>

			<div class="btn-group-sm" id="toolbar" role="group">
				<a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:appointment:add">
	                <i class="fa fa-plus"></i> 新增
	            </a>
	        </div>

	        <div class="col-sm-12 select-table table-striped">
			    <table id="bootstrap-table"></table>
			</div>
		</div>
	</div>
	<th:block th:include="common/include :: footer" />
	<!--也就是说这个插件有着分页的功能：里面默认有
	pageSize: 10
	pageNum: 1
	orderByColumn: seq
	isAsc: asc
	-->
	<script th:inline="javascript">
		// var editFlag = [[${@permission.hasPermi('system:appointment:edit')}]];
		// var removeFlag = [[${@permission.hasPermi('system:appointment:remove')}]];
		// var datas = [[${@dict.getType('sys_normal_disable')}]];

		var serviceTypeDatas=[[${@dict.getType('cmi_service_type')}]];//服务类型的字典数据
		var statusDatas=[[${@dict.getType('cmi_status')}]];//根据字典类型获取状态的字典数据
		var prefix = ctx + "/business/appointment";
		$(function() {
		    var options = {
		        url: prefix + "/query",
		        createUrl: prefix + "/addPage",
		        updateUrl: prefix + "/editPage?id={id}",
		        removeUrl: prefix + "/remove",
		        exportUrl: prefix + "/export",
		        sortName: "seq",
				uniqueId:'id',//必须有，可用提供传递的id值，获取对应行的数据
		        modalName: "预约",
		        columns: [//对应table的表头信息
				// {
		        //     checkbox: true
		        // },
		        {
		            field: 'id',
		            title: '预约id',
					visible: false
		        },
		        {
		            field: 'customerName',
		            title: '客户姓名',
		            sortable: true
		        },
		        {
		            field: 'customerPhone',
		            title: '联系方式',
		            sortable: true
		        },
				{
					field: 'appointmentTime',
					title: '预约时间',
					sortable: true
				},
				{
					field: 'actualArrivalTime',
					title: '到店时间',
					sortable: true
				},
				{
					field: 'licensePlate',
					title: '车牌号码',
					sortable: true
				},
				{
					field: 'carSeries',
					title: '汽车类型',
					sortable: true
				},
				{
					field: 'serviceType',
					title: '服务类型',
					align: 'center',
					formatter: function(value, row, index) {//当前字段的值和与数据库查询出的value比对，是否显示数据库label
						// console.log(value, datas);
						return $.table.selectDictLabel(serviceTypeDatas, value);
					}
				},
				{
					field: 'info',
					title: '备注信息',
					sortable: true
				},
				{
					field: 'status',
					title: '预约的状态',
					align: 'center',
					formatter: function(value, row, index) {//当前字段的值和与数据库查询出的value比对，是否显示数据库label
						return $.table.selectDictLabel(statusDatas, value);
					}
				},
		        {
		            title: '操作',
		            align: 'center',
		            formatter: function(value, row, index) {
		            	//操作行时，变量必须在这定义
						var editFlag='';
						var arrivalFlag='';
						var jisuanFlag='';
						var removeFlag='';
						var cancelFlag='';

						//根据预约单的不同状态判断能否使用按钮：其实就是disabled属性
						//先显示编辑和到店2个按钮
						if(row.status==0){//如果是预约则结算不可用，其他可用
							jisuanFlag+='disabled';
						}else if(row.status==1){//如果到店，则只有结算单可用，其他不可用
							editFlag+='disabled';
							arrivalFlag+='disabled';
							removeFlag+='disabled';
							cancelFlag+='disabled';
						}else if(row.status==2){//当记录状态是用户取消，编辑，到店，取消，删除, 结算单不可用
							editFlag+='disabled';
							arrivalFlag+='disabled';
							removeFlag+='disabled';
							cancelFlag+='disabled';
							jisuanFlag+='disabled';
						}else if(row.status==4){//当记录状态是结算单生成，编辑，到店，取消，删除不可用, 结算单可用
							editFlag+='disabled';
							arrivalFlag+='disabled';
							removeFlag+='disabled';
							cancelFlag+='disabled';
						}

						var actions = [];
		                actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" ' +
								'onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
						actions.push('<a class="btn btn-success btn-xs ' + arrivalFlag + '" href="javascript:void(0)" ' +
								'onclick="arrival(\'' + row.id + '\')"><i class="fa fa-edit"></i>到店</a> ');

						actions.push('<a class="btn btn-success btn-xs ' + jisuanFlag + '" href="javascript:void(0)" ' +
								'onclick="generateStatement(\'' + row.id + '\')"><i class="fa fa-edit"></i>结算单</a> ');

						var more = [];
						more.push("<a class='btn btn-default btn-xs "+cancelFlag+"' href='javascript:void(0)' " +
								"onclick='cancelHandler(" + row.id + ")'><i class='fa fa-reply'></i>取消</a> ");
						more.push("<a class='btn btn-default btn-xs "+removeFlag+"' href='javascript:void(0)' " +
								"onclick='remove(" + row.id + ")'><i class='fa fa-remove'></i>删除</a>");
						actions.push('<a tabindex="0" class="btn btn-info btn-xs" role="button" data-container="body" data-placement="left" data-toggle="popover" data-html="true" data-trigger="hover" ' +
								'data-content="' + more.join('') + '"><i class="fa fa-chevron-circle-right"></i>更多操作</a>');
		                return actions.join('');
		            }
		        }]
		    };
		    $.table.init(options);
		});
		//到店:发送ajax请求
		function arrival(id) {
			$.modal.confirm("是否到店？",function () {
				//发送ajax请求
				$.operate.submit(prefix+"/arrivaled?id="+id,"post");
			});
		}
		//取消
		function cancelHandler(id) {
			$.modal.confirm("是否确认取消？",function() {
				$.operate.submit(prefix+"/cancel?id="+id,"post");
			});
		}
		//软删除
		function remove(id) {
			$.modal.confirm("确认是否删除？",function () {
				$.operate.submit(prefix+"/remove?id="+id,"post");
			});
		}
		//生成结算单
		function generateStatement(id){
			//获取这一行数据
			var row = $("#bootstrap-table").bootstrapTable("getRowByUniqueId",id);
			alert(row);//为null?
			var msg = "确认生成结算单吗?";
			if(row.status==4){
				msg = "是否需要查看对应的结算单明细";//这里要跳转到结算单显示页面的话，必须有结算单id
			}
			$.modal.confirm(msg, function() {
				alert("1111")
				$.operate.post(prefix + "/generateStatement",{appointmentId:id},function(result){
					if(result.code==web_status.SUCCESS){
						var url = ctx + "business/statementItem/itemDetail?statementId=" + result.data;
						$.modal.openTab("结算单明细", url);
					}
				});
			});
		}
	</script>
</body>
</html>